/*
 * Copyright 2023-2085 xujin <ceo@itgrail.com>
 *
 * Licensed under the Grail License, Version 1.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://itgrail.com/docs?id=3&catalogId=87
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.itgrail.pilot.infrastructure.tunnel.db.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itgrail.pilot.infrastructure.tunnel.db.dataobject.DictDataDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DictDataMapper extends BaseMapper<DictDataDO> {


    @Select("SELECT * FROM t_dict_data where is_deleted=0 and dict_code=#{dictCode}")
    List<DictDataDO> findDictDataByDictCode(@Param("dictCode") String dictCode);

    @Update("update t_dict_data set is_deleted=1  where dict_code=#{dictCode} ")
    void batchDeleteDictDataByDictCode(@Param("dictCode") String dictCode);

    @Select("SELECT * FROM t_dict_data where is_deleted=0 and status=#{status} and dict_code=#{dictCode}")
    List<DictDataDO> findDictDataByDictCodeAndStatus(@Param("dictCode") String dictCode, @Param("status") int status);


    @Select("SELECT * FROM t_dict_data where is_deleted=0 and dict_code=#{dictCode} and item_code=#{itemCode}")
    DictDataDO findDictDataByDictCodeAndItemCode(@Param("dictCode") String dictCode, @Param("itemCode") String itemCode);


    /**
     * 根据字典类型，是否启用和数据项code查询
     *
     * @param dictCode
     * @param status
     * @param itemCode
     * @return
     */
    @Select("SELECT * FROM t_dict_data where is_deleted=0 and status=#{status} and dict_code=#{dictCode} and item_code=#{itemCode}")
    DictDataDO findDictDataByDictCodeAndStatusAndItemCode(@Param("dictCode") String dictCode, @Param("status") int
            status, @Param("itemCode") String itemCode);


}
